package com.ls.thread;

/**
 * sleep 和 wait的异同
 */
public class WaitVsSleep {
    private static final Class<WaitVsSleep> LOCK = WaitVsSleep.class;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            synchronized (LOCK){
                try {
//                    LOCK.wait(); // 会立即释放锁 ,主线程的方法会执行
                    Thread.sleep(1000*30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t1");

        t1.start();
        Thread.sleep(100);
        synchronized (LOCK){
            System.out.println("hello world");
        }

    }
}
